package in.co.codedoc.sql;

import java.io.IOException;
import java.io.PrintWriter;

public class TransformedTableColumn
	implements TableColumn
{
	public TransformedTableColumn(String function,TableColumn wrappedColumn)
	{
		this.function = function;
		this.wrappedColumn = wrappedColumn;
	}
	
	@Override
	public PrintWriter Generate(PrintWriter out)
		throws IOException
	{
		out.print(function);
		out.print("(");
		wrappedColumn.Generate(out);
		out.print(")");
		return out;
	}

	@Override
	public DBOutputColumnMap GetDBOutputColumnMap()
	{
		return wrappedColumn.GetDBOutputColumnMap();
	}

	@Override
	public String GetName()
	{
		return function  + "(" + wrappedColumn.GetName() + ")";
	}

	@Override
	public String GetQualifiedName()
	{
		return function  + "(" + wrappedColumn.GetQualifiedName() + ")";
	}

	@Override
	public Table GetTable()
	{
		return wrappedColumn.GetTable();
	}

	@Override
	public boolean equals(Object t)
	{
		if(t == null || !(t instanceof TransformedTableColumn))
		{
			return false;
		}

		TransformedTableColumn that = (TransformedTableColumn)t;

		return function != null && function.equals(that.function) && wrappedColumn.equals(that.wrappedColumn);
	}

	@Override
	public int hashCode()
	{
		return function.hashCode()^wrappedColumn.hashCode();
	}

	
	private String function; 
	private TableColumn wrappedColumn;


}
